package com.zmn.oms.dubbo.impl.zmn.master.quotation;

import com.alibaba.fastjson.JSON;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.business.interfaces.master.MasterQuotationBRateService;
import com.zmn.oms.dubbo.dto.zmn.master.MasterQuotationRateRankingDRO;
import com.zmn.oms.dubbo.interfaces.zmn.master.quotation.MasterQuotationRateService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.vo.master.QuotationRateRankingVO;
import com.zmn.oms.model.vo.master.QuotationRateVO;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author ：SongWeidong
 * @date ：2021/3/2 15:33
 * @description：计价器使用率
 */
@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class MasterQuotationRateServiceImpl implements MasterQuotationRateService {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private MasterQuotationBRateService masterQuotationBRateService;

    /**
     * 查询师傅计价器使用率
     *
     * @return
     */
    @Override
    public List<MasterQuotationRateRankingDRO> getMasterQuotationRateRanking(Integer masterId, Integer orgThrId) {

        // 查询使用率列表
        List<QuotationRateVO> voList = masterQuotationBRateService.queryQuotation(orgThrId);
        // 查询工程师排名
        logger.debug("查询工程师计价器排名：{}", JSON.toJSONString(voList));
        List<QuotationRateRankingVO> ranking = masterQuotationBRateService.getRanking(voList, masterId);

        return BeanMapper.mapList(ranking, MasterQuotationRateRankingDRO.class);
    }
}
